//
//  XKLRecommendTagCell.m
//  GuiZiShouDuanZi
//
//  Created by xmg on 16/4/27.
//  Copyright © 2016年 xiao_kl. All rights reserved.
//

#import "XKLRecommendTagCell.h"
#import <UIImageView+WebCache.h>
#import "XKLRecommendTagItem.h"
@interface XKLRecommendTagCell()
@property (weak, nonatomic) IBOutlet UIImageView *myImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLable;
@property (weak, nonatomic) IBOutlet UILabel *recomLable;

@end

@implementation XKLRecommendTagCell

- (void)awakeFromNib {
   
}

-(void)setItem:(XKLRecommendTagItem *)item{
    _item=item;
//    [self.myImageView sd_setImageWithURL:[NSURL URLWithString:item.image_list] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"]];
    
    [self.myImageView sd_setImageWithURL:[NSURL URLWithString:item.image_list] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        if (image==nil) return ;
        
        //开启上下文
        UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
        
        //描述剪切局域
        UIBezierPath *clipPath=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
        
        //裁剪
        [clipPath addClip];
        
        //画图
        [image drawAtPoint:CGPointZero];
        
        //获取图片
        UIImage *newImage=UIGraphicsGetImageFromCurrentImageContext();
        
        //关闭上下文
        UIGraphicsEndImageContext();
        
        //设置图片
        self.myImageView.image=newImage;
        
    }];
    
    
    
    self.nameLable.text=item.theme_name;
    
    self.recomLable.text=[NSString stringWithFormat:@"%.1lf万人订阅",item.sub_number/10000.0];
}

-(void)beginText{
    //开启上下文;
    UIGraphicsBeginImageContext(self.myImageView.image.size);
    
    
}

- (IBAction)butClick:(id)sender {
    XKLLog(@"订阅");
}

//重写cell的setFrame方法
-(void)setFrame:(CGRect)frame{
    frame.origin.x=5;
    frame.size.width-=frame.origin.x * 2;
    frame.size.height-=1;
    [super setFrame:frame];

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}

@end
